package com.xxxx.seckill.listen;

import com.xxxx.seckill.pojo.Order;
import com.xxxx.seckill.pojo.dto.MqDto;
import com.xxxx.seckill.service.IOrderService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.xxxx.seckill.pojo.MqNames.EXCHANGE_TOPIC;
import static com.xxxx.seckill.pojo.MqNames.TOPIC_QUEUE;

@Component
public class RabbitMqListener {
    @Autowired
    private IOrderService iOrderService;

    /**
     * 监听下单消息
     * @param mqDto
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = TOPIC_QUEUE),
            exchange = @Exchange(name = EXCHANGE_TOPIC ,type = "topic"),
            key = "order.#"
    ))
    public void listenOrder(MqDto mqDto){
        Order order = iOrderService.order(mqDto.getUser(), mqDto.getGoodsId());

    }
}
